<template>
  <div id="character-story" :class="{ h5: this.$store.state.webType === 'h5' }">
    <el-row :span="24" class="page">
      <!-- 面包屑 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">{{ $t("home") }} </el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t("sections") }}</el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t("people") }}</el-breadcrumb-item>
      </el-breadcrumb>

      <div class="banner-view">
        <div class="banner-col" @click="$goDetail(bigBanner.id)">
          <div class="img-view scale-view">
            <img
              class="banner-big"
              :src="bigBanner.imgUrlMax"
              :alt="$store.state.lang == 'CN' ? bigBanner.title : bigBanner.titleEnglish"
            />
          </div>
          <div class="item-title two-line">
            {{ $store.state.lang == "CN" ? bigBanner.title : bigBanner.titleEnglish }}
          </div>
        </div>
        <div class="four-col">
          <div
            class="four-item"
            v-for="(item, index) in bannerData"
            :key="index"
            @click="$goDetail(item.id)"
          >
            <div class="img-view scale-view">
              <img class="banner-big" :src="item.imgUrlMax" :alt="item.title" />
            </div>
            <div class="item-title two-line">
              {{ $store.state.lang == "CN" ? item.title : item.titleEnglish }}
            </div>
          </div>
        </div>
      </div>

      <el-row :span="24" class="art-row">
        <div class="art-col">
          <!-- 文章label的tab -->
          <div class="art-tab">
            <div
              class="tab-item"
              @click="changeLabel('', '')"
              :class="{ active: currentLabel == '' }"
            >
              {{ $t("all") }}
            </div>
            <template v-if="labelData && labelData.length > 0">
              <div
                class="tab-item"
                @click="changeLabel(item.id, item.label)"
                :class="{ active: currentLabel == item.label }"
                v-for="(item, index) in labelData"
                :key="index"
              >
                {{ item.label }}
              </div>
            </template>
            <!-- 右侧切换视图和总条数 -->
            <div class="tab-info">
              <div class="info-total">
                {{
                  $t("results").length > 6
                    ? listTotal + " " + $t("results")
                    : `共
                ${listTotal} 条`
                }}
              </div>
              <div class="toggle-img" @click="viewTypeChange('img')">
                <img
                  v-if="currentView !== 'img'"
                  src="@/assets/images/use/art-view01.png"
                  title="图文列表"
                />
                <img
                  v-if="currentView === 'img'"
                  src="@/assets/images/use/art-view11.png"
                  title="图文列表"
                />
              </div>
              <div class="toggle-text" @click="viewTypeChange('text')">
                <img
                  v-if="currentView !== 'text'"
                  src="@/assets/images/use/art-view02.png"
                  title="文字列表"
                />
                <img
                  v-if="currentView === 'text'"
                  src="../assets/images/use/art-view22.png"
                  title="文字列表"
                />
              </div>
            </div>
          </div>
          <infinite-scroll class="infinite" @loadBottom="loadMore">
            <div
              class="art-view"
              v-masonry
              :horizontal-order="true"
              transition-duration="0s"
              item-selector=".art-item"
              :fit-width="false"
              :gutter="gutterWidth"
              style="height: auto"
              :class="{ text: currentView === 'text' }"
            >
              <template v-if="currentView === 'img'">
                <div
                  class="art-item scale-view"
                  v-masonry-tile
                  v-for="(img, idx) in artData"
                  @click="$goDetail(img.id)"
                  :key="idx"
                >
                  <img :src="img.imgUrl" :alt="img.title" />
                  <div class="art-content">
                    <div class="item-title two-line">
                      {{ img.title }}
                    </div>
                    <div class="item-info">
                      <div
                        class="info-label"
                        v-if="img.label && img.label.length > 0 && $store.state.lang === 'CN'"
                      >
                        {{ currentLabel ? currentLabel : img.label[0] }}
                      </div>
                      <div class="info-time">{{ img.peridos }}</div>
                    </div>
                    <div class="item-content">{{ img.content }}</div>
                  </div>
                </div>
              </template>
              <template v-else>
                <div
                  class="art-item"
                  v-masonry-tile
                  @click="$goDetail(img.id)"
                  v-for="(img, idx) in artData"
                  :key="idx"
                >
                  <div class="art-content">
                    <div class="item-title">
                      {{ img.title }}
                      <div class="item-info">
                        <div
                          class="info-label"
                          v-if="img.label && img.label.length > 0 && $store.state.lang === 'CN'"
                        >
                          {{ currentLabel ? currentLabel : img.label[0] }}
                        </div>
                        <div class="info-time">{{ img.peridos }}</div>
                      </div>
                    </div>
                    <div class="item-content">{{ img.content }}</div>
                  </div>
                </div>
              </template>
              <div v-if="listQuery.pageNum < maxPage" class="art-more true" @click="getListMore()">
                {{ $t("more2") }} >
              </div>
              <div v-else class="art-more none">{{ $t("noMore") }}</div>

              <goTop></goTop>
            </div>
          </infinite-scroll>
        </div>
        <!-- 右侧{{$t('latest')}} 热点文章 -->
        <div class="row-right">
          <!-- {{$t('latest')}} -->
          <hot-article></hot-article>
          <new-book></new-book>
        </div>
      </el-row>
    </el-row>
  </div>
</template>

<script>
import goTop from "../components/goTop";
import HotArticle from "@/components/HotArticle";
import NewBook from "@/components/NewBook";

export default {
  name: "CharacterStory",
  components: {
    goTop,
    HotArticle,
    NewBook,
  },
  data() {
    return {
      busy: true,
      nomore: false,
      gutterWidth: 20,

      // 左侧大图
      bigBanner: {},
      // banner数据
      bannerData: [],
      // 当前展示的banner index
      currentIndex: 0,
      // {{$t('latest')}}
      bookData: {},
      // 热点文章
      articleData: [],
      // 当前文章列表展示形式
      currentView: "img",
      // 文章列表
      artData: [],
      // 文章总数量
      listTotal: 0,
      maxPage: 1,
      // 文章列表请求信息
      listQuery: {
        columnId: "",
        labelId: "",
        pageSize: 10,
        pageNum: 1,
      },
      // 标签
      labelData: [],
      currentLabel: "",
    };
  },
  mounted() {
    if (this.$route.query.token) {
      sessionStorage.setItem("token", this.$route.query.token);
    }
    this.listQuery.columnId = this.$getPartId(this.$route.path);
    this.listQuery.menuId = this.$getMenuId(this.$route.path);
    this.getList();
    this.getBanner();
    this.getLabels();
  },
  methods: {
    async loadMore() {
      // console.log(
      //   "loadMore",
      //   this.busy || this.listQuery.pageNum >= this.maxPage
      // );
      if (this.busy || this.listQuery.pageNum >= this.maxPage) return;
      this.busy = true;
      this.listQuery.pageNum += 1;
      await this.getList();
    },
    async getList() {
      this.$get(this.$api + "/cms/web/selsctWeb", this.listQuery).then((res) => {
        this.artData = [...this.artData, ...res.data];
        this.listTotal = res.total;
        this.maxPage = res.maxPage;

        let that = this;
        this.$nextTick(() => {
          that.nomore = true;
          setTimeout(() => {
            that.busy = false;
          }, 300);
        });
      });
    },
    changeLabel(id, label) {
      this.listQuery.labelId = id;
      this.listQuery.pageNum = 1;
      this.currentLabel = label;
      this.artData = [];
      this.getList();
    },
    getLabels() {
      this.$get(this.$api + "/cms/web/getLabelByPartId", {
        partId: this.listQuery.columnId,
      }).then((res) => {
        this.labelData = res.data;
      });
    },
    getListMore() {
      this.listQuery.pageNum += 1;
      this.getList();
    },
    getBanner() {
      this.$get(this.$api + "/cms/web/partArticleBanner", {
        menuId: this.listQuery.menuId,
      }).then((res) => {
        res.data.forEach((item) => {
          if (item.bannerName === "左侧大图") {
            this.bigBanner = item;
          } else {
            this.bannerData.push(item);
          }
        });
        //  console.log(res, this.bigBanner, this.bannerData);
      });
    },
    viewTypeChange(type) {
      this.artData = [];
      this.listQuery.pageNum = 1;
      this.getList();
      this.currentView = type;
      this.$nextTick(() => {
        this.$redrawVueMasonry();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
#character-story {
  position: relative;
  width: 100%;
  background-color: rgba(15, 0, 0, 0.5);

  &::after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    background: url("../assets/images/rwgs-bg.png") no-repeat;
    background-size: 100% auto;
    background-position: center 0;
  }

  .page {
    padding: fh(152vh, pc) fw(80vw, pc) fh(40vh, pc) fw(80vw, pc);
    background: #fff;

    ::v-deep .el-breadcrumb {
      // margin-left: fw(-40vw, pc);
      .el-breadcrumb__inner {
        font-weight: bold;
        color: #fff !important;
        font-size: fh(18vh, pc);
      }
    }
  }

  .art-row {
    display: flex;
    padding-top: fh(28vh, pc);
    width: 100%;

    .book-content {
      background-color: $fh90;
      padding-bottom: fh(40vh, pc);

      .book-btn {
        display: flex;
        width: 100%;
        align-items: flex-end;
        justify-content: center;

        img {
          width: fw(180vw, pc);

          &:hover {
            cursor: pointer;
            opacity: 0.7;
          }
        }
      }

      .book-row {
        display: flex;
        width: 100%;
        padding: fh(46vh, pc) fw(20vw, pc);
        color: $sh;

        img.book-img {
          width: fw(280vw, pc);
        }

        .book-text {
          padding-left: fw(10vw, pc);

          .view-label {
            color: $zh;
            position: relative;
            display: inline-block;
            font-size: fh(24vh, pc);
            font-weight: 800;
            margin-top: fh(20vh, pc);
            margin-bottom: fh(60vh, pc);

            &::after {
              content: "";
              position: absolute;
              bottom: fh(-16vh, pc);
              right: fw(-12vw, pc);
              width: fw(30vw, pc);
              height: fh(18vh, pc);
              border-right: fw(6vw, pc) solid hsla(14, 74%, 37%, 0.2);
              border-bottom: fw(8vw, pc) solid hsla(14, 74%, 37%, 0.2);
            }
          }

          .text-item {
            padding-bottom: fh(30vh, pc);

            .item-title {
              color: $sh;
              font-size: fh(18vh, pc);
              font-weight: bold;
              padding-bottom: fh(20vh, pc);
            }

            .item-content {
              font-size: fh(16vh, pc);
              line-height: fh(26vh, pc);
            }
          }
        }
      }
    }

    .row-right {
      display: flex;
      flex: 1;
      margin-left: fw(20vw, pc);
      flex-flow: column;

      .hot-article {
        width: 100%;
        padding: fh(30vh, pc) fw(30vw, pc);
        background-color: $fh90;
        margin-top: 0;

        .article-label {
          color: $zh;
          position: relative;
          display: inline-block;
          font-size: fh(24vh, pc);
          font-weight: 800;
          margin-top: fh(20vh, pc);
          margin-bottom: fh(60vh, pc);

          &::after {
            content: "";
            position: absolute;
            bottom: fh(-16vh, pc);
            right: fw(-12vw, pc);
            width: fw(30vw, pc);
            height: fh(18vh, pc);
            border-right: fw(6vw, pc) solid hsla(14, 74%, 37%, 0.2);
            border-bottom: fw(8vw, pc) solid hsla(14, 74%, 37%, 0.2);
          }
        }

        .article-view {
          color: $sh;

          .article-item {
            width: fw(485vw, pc);
            line-height: fh(26vh, pc);
            margin-bottom: fh(26vh, pc);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;

            span {
              color: $zh;
              font-size: fh(18vh, pc);
              font-weight: bold;
              display: inline-block;
              padding-right: fw(16vw, pc);
            }

            &:hover {
              opacity: 0.8;
              cursor: pointer;
              color: $zh;
            }
          }
        }
      }
    }
  }

  .art-col {
    position: relative;
    width: fw(1180vw, pc);
    margin-top: fh(20vh, pc);

    .art-tab {
      width: 100%;
      display: flex;
      align-items: center;
      margin-bottom: fh(30vh, pc);
      color: $sh;

      .tab-item {
        margin-right: fw(60vw, pc);
        font-size: fh(16vh, pc);
        position: relative;
        line-height: fh(24vh, pc);

        &:hover {
          color: $sh;
          cursor: pointer;
        }

        &.active {
          font-size: fh(20vh, pc);
          font-weight: bold;
          color: $sh;

          &::before {
            content: "";
            position: absolute;
            bottom: fh(-14vh, pc);
            width: 100%;
            border-top: fh(6vh, pc) solid $zh;
          }
        }
      }

      .tab-info {
        margin-left: auto;
        display: flex;
        align-items: center;

        .toggle-img {
          margin-left: fh(62vw, pc);
          margin-right: fh(24vw, pc);
        }

        img {
          width: fw(20vw, pc);
          cursor: pointer;
        }
      }
    }

    .art-view {
      cursor: pointer;

      &.text {
        .art-item {
          width: 100%;
        }

        .item-title {
          color: $sh;
          display: flex;
          width: 100%;

          .item-info {
            padding-left: fw(40vw, pc);
            margin-left: auto;
            width: max-content !important;

            .info-label {
              margin-right: fw(20vw, pc);
              width: max-content !important;
            }

            .info-time {
              width: max-content;
              margin-left: fw(20vw, pc) !important;
            }
          }
        }
      }

      .art-item {
        // break-inside: avoid;
        width: calc((100% - 40px) / 3);
        margin-bottom: fh(20vh, pc);
        background-color: $dh;

        &:hover {
          opacity: 0.9;
        }

        cursor: pointer;

        img {
          width: 100%;
        }

        .art-content {
          width: 100%;
          color: rgba(251, 254, 255, 0.8);
          padding: fh(20vh, pc) fw(20vw, pc);
          position: relative;
          z-index: 2;
          background-color: $dh;

          .item-title {
            color: $sh;
            line-height: 130%;
            font-size: fh(16vh, pc);
            margin-bottom: fh(8vh, pc);
            font-weight: 600;
            // color: #fff;
          }

          .item-info {
            display: flex;
            align-items: center;
            width: 100%;
            justify-content: space-between;
            margin-bottom: fh(0vh, pc);
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);

            .info-time {
              color: #a1b8bd;
              margin-left: auto;
            }
          }

          .item-content {
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);
            font-weight: 400;
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }

    .art-more {
      width: max-content;
      margin: fh(40vh, pc) auto;
      color: $sh;
      font-size: fh(14vh, pc);

      &.true:hover {
        cursor: pointer;
        opacity: 0.8;
        color: $zh;
      }

      &.none {
        opacity: 0.5;
      }
    }
  }

  .banner-view {
    display: flex;
    width: 100%;
    margin-top: fh(16vh, pc);

    .banner-col {
      position: relative;
      width: fw(800vw, pc);
      overflow: hidden;
      margin-right: fw(46vw, pc);

      .img-view {
        // width: fw(800vw, pc);
        // height: fh(738vh, pc);
        // overflow: hidden;

        .banner-big {
          width: 100%;
        }
      }
    }

    .item-title {
      color: $sh;
      //position: absolute;
      width: 100%;
      display: flex;
      width: 100%;
      align-items: center;
      height: fh(82vh, pc);
      padding: fh(10vh, pc) fw(24vw, pc);
      bottom: 0;
      color: $sh;
      font-size: fh(20vh, pc);
      line-height: fh(30vh, pc);
      background-color: rgba(245, 245, 245, 0.7);
    }

    .four-col {
      display: flex;
      align-items: flex-start;
      flex-wrap: wrap;
      flex: 1;
      justify-content: space-between;

      .four-item {
        position: relative;
        width: fw(440vw, pc);
        margin-bottom: fw(40vw, pc);

        &:nth-last-child(1),
        &:nth-last-child(2) {
          margin-bottom: 0;
        }

        .img-view {
          // width: 100%;
          // height: fh(308vh, pc);
          // overflow: hidden;

          img {
            width: 100%;
            display: block;
          }
        }
      }
    }
  }
}

#character-story.h5 {
  .art-col {
    margin-top: 0;

    .art-view {
      &.text {
        .art-item {
          width: 100%;
        }
      }

      .art-item {
        width: calc(50% - 10px);
        margin-bottom: fw(8vw, h5);

        .art-content {
          padding: fw(8vw, h5) !important;
        }
      }
    }
  }

  .banner-view {
    flex-wrap: wrap;

    .banner-col {
      width: 100%;
      margin-bottom: fh(5vh, h5);

      .banner-big {
        width: 100%;
      }
    }

    .four-col {
      width: 100%;

      .four-item {
        width: 49%;
        margin-bottom: fh(5vh, h5);

        .item-title {
          color: $sh;
          width: 100%;
          padding: fw(4vw, h5) fw(4vw, h5) !important;
          height: fh(56vh, h5);
          line-height: fh(20vh, h5);
          font-size: fh(14vh, h5);
        }
      }
    }
  }
}
</style>
